
public class SequenceGapBuffer<T> implements GapBuffer<T> {

	private CircularArraySequence<T> leftBuffer = new CircularArraySequence<T>(100);
	private CircularArraySequence<T> rightBuffer = new CircularArraySequence<T>(100);
	
	
	@Override
	public void insert(T item) {
		leftBuffer.append(item);
	}

	@SuppressWarnings("unchecked")
	@Override
	public void cursorLeft() {
		rightBuffer.prepend((T) leftBuffer.array[leftBuffer.last]);
		leftBuffer.array[leftBuffer.last] = null;
		leftBuffer.decLastPtr();
	}

	@Override
	public void delete() {
		if(leftBuffer.isEmpty() == false) {
			leftBuffer.array[leftBuffer.last] = null;
			leftBuffer.decLastPtr();
		}
	}

	@SuppressWarnings("unchecked")
	@Override
	public void cursorRight() {
		leftBuffer.append((T) rightBuffer.array[rightBuffer.head]);
		rightBuffer.array[rightBuffer.head] = null;
		rightBuffer.incHeadPtr();
	}
	
	public String toString() {
		return leftBuffer.toString()+"^"+rightBuffer.toString();
	}

}
